﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Windows.Controls;

namespace SHomeWorkshop.LunarSF.StudentInfosManager.ValidationRules
{
    /// <summary>
    /// 邮政编码验证类。
    /// </summary>
    public class PostCodeRule : LValidationRule
    {
        public override ValidationResult Validate(object value, System.Globalization.CultureInfo cultureInfo)
        {
            string strValue = Format(value.ToString());
            string expression = @"^\d{6}$";
            if (Regex.IsMatch(strValue, expression, RegexOptions.Compiled))
                return new ValidationResult(true, null); //验证OK
            else
                return new ValidationResult(false, "邮政编码必须是6位数字"); //验证失败
        }

        public static string Format(string origin)
        {
            if (string.IsNullOrWhiteSpace(origin)) return "";

            return FullCharsToHalf(origin);
        }
    }
}
